import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useLocation, useNavigate } from 'react-router-dom';

function RoutrSW(props: any) {
    const location = useLocation()
    const token = useSelector((state: any) => state.userInfo.token)
    const navigate = useNavigate()
    //只要路由改变，就验证token是否存在
    useEffect(() => {
        if (!token) {
            navigate('/login')
        } else if (location.pathname == '/login')
            navigate('/index')
    }, [location.pathname])
    return (
        <div>

        </div>
    );
}

export default RoutrSW;